﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using Yipusoft.SystemSet;

namespace SmsSeries
{
    public partial class frmSetup : Form
    {
        public frmSetup()
        {
            InitializeComponent();
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("请确认是否保存数据？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                SaveData();
                Application.Restart();
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void frmSetup_Load(object sender, EventArgs e)
        {
            Init();
        }

        private void SaveData()
        {
            Func.WriteItem("Yipusoft\\SmsSeries", "SQLServerName", tbSQLServerName.Text);
            Func.WriteItem("Yipusoft\\SmsSeries", "SQLUserName", tbSQLUserName.Text);
            Func.WriteItem("Yipusoft\\SmsSeries", "SQLPassword", tbSQLPassword.Text);
        }

        private void Init()
        {
            RegistryKey hkml = Registry.LocalMachine;
            RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
            hkml = Registry.LocalMachine;
            software = hkml.OpenSubKey("SOFTWARE", true);
            RegistryKey command = software.OpenSubKey("Yipusoft\\SmsSeries", true);
            if (command == null)
            {
                command = software.CreateSubKey("Yipusoft\\SmsSeries", RegistryKeyPermissionCheck.Default);
                //数据库服务器地址
                command.SetValue("SQLServerName", "");
                //数据库用户名
                command.SetValue("SQLUserName", "");
                //数据库密码
                command.SetValue("SQLPassword", "");
            }

            tbSQLServerName.Text = Func.GetItem("Yipusoft\\SmsSeries", "SQLServerName");
            tbSQLUserName.Text = Func.GetItem("Yipusoft\\SmsSeries", "SQLUserName");
            tbSQLPassword.Text = Func.GetItem("Yipusoft\\SmsSeries", "SQLPassword");
        }
    }
}
